package cn.zpro.jeecg.mvc.util;

import java.lang.annotation.Annotation;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

import cn.zpro.jeecg.mvc.annotation.Mvc;
import cn.zpro.jeecg.mvc.annotation.MvcMapping;
import cn.zpro.jeecg.mvc.controller.DepAction;

public class AnnotationUtil {

	public static void main(String[] args) throws Exception {

	}

	public static String checkAnnotation(Class<?> clazz, String actionName,
			String method) {
		Boolean flag = clazz.isAnnotationPresent(Mvc.class);
		if (flag) {
			Class<?> cl = clazz;
			String methodVal = "";
			if (cl.getName().contains(actionName)) {// 判断是否是访问的Action类
				for (Method m : cl.getMethods()) {
					MvcMapping mapping = m.getAnnotation(MvcMapping.class);
					if (mapping != null) {
						// System.out.println(mapping.value());
						// 反射调用
						if (method.equals(mapping.value())) {
							methodVal = invoke(clazz, mapping.value())
									.toString();
						}
						return methodVal;
					}
				}
			}

		}
		return "";
	}

	public static Object invoke(Class<?> clazz, String methodName) {

		Method method;
		Object result = null;
		try {
			method = clazz.getMethod(methodName);
			result = method.invoke(clazz.newInstance());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		// 调用Person的sayHello方法

		return result;
	}
}
